# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.html

import scrapy
from scrapy.utils.project import get_project_settings
from itemloaders.processors import TakeFirst, MapCompose


def item_trading_link(value=""):
    bitcoin_host = get_project_settings().get('BITCOIN_HOST')
    return "{host}zh/bitcoin/{value}".format(host=bitcoin_host, value=value.replace("../", ""))


class BitcoinCrawlerItem(scrapy.Item):
    default_output_processor = TakeFirst()

    # 排名
    index = scrapy.Field(
        output_processor=default_output_processor
    )
    # 币种名称
    coin_name = scrapy.Field(
        output_processor=default_output_processor
    )
    # 地址
    address = scrapy.Field(
        output_processor=default_output_processor
    )
    # 交易信息列表地址
    link = scrapy.Field(
        output_processor=default_output_processor
    )
    # coin总数
    total_coin = scrapy.Field(
        output_processor=default_output_processor
    )
    # 交易block
    info_block = scrapy.Field(
        output_processor=default_output_processor
    )
    # 交易详情
    trading_link = scrapy.Field(
        input_processor=MapCompose(item_trading_link),
        output_processor=default_output_processor
    )
    # 交易时间
    info_time = scrapy.Field(
        output_processor=default_output_processor
    )
    # 交易量
    info_num = scrapy.Field(
        output_processor=default_output_processor
    )
    # 持有量
    info_total = scrapy.Field(
        output_processor=default_output_processor
    )
    # 总资产/单价($)
    info_total_usd = scrapy.Field(
        output_processor=default_output_processor
    )
